import { Router } from 'express';
import sysConfigController from '@/controllers/system/sys-config.controller';
import { authMiddleware } from '@/middlewares/auth.middleware';
import { permissionMiddleware } from '@/middlewares/permission.middleware';
import { validateConfigInfo, validateConfigKey, validateConfigCreate, 
         validateConfigEdit, validateConfigRemove } from '@/validators/system/config.validator';
import { createController } from '@/utils/router/route.controller';

const router = createController(Router());

/**
 * 参数配置路由
 * 路径前缀：/system/config
 */

// ================== 参数配置相关 ==================

// 所有路由均需认证
router.use(authMiddleware);

// 参数设置列表
router.get('/list', permissionMiddleware('system:config:list'), sysConfigController.list);

// 根据参数键名查询参数值
router.get('/configKey/:configKey', permissionMiddleware('system:config:query'), validateConfigKey, sysConfigController.getConfigKey);

// 获取参数详细信息
router.get('/:configId', permissionMiddleware('system:config:query'), validateConfigInfo, sysConfigController.getInfo);

// 新增参数配置
router.POST('/', permissionMiddleware('system:config:add'), validateConfigCreate, sysConfigController.add);

// 修改参数配置
router.PUT('/', permissionMiddleware('system:config:edit'), validateConfigEdit, sysConfigController.edit);

// 刷新参数缓存
router.DELETE('/refreshCache', sysConfigController.refreshCache);

// 删除参数配置
router.DELETE('/:configIds', permissionMiddleware('system:config:remove'), validateConfigRemove, sysConfigController.remove);

// 导出参数配置
router.post('/export', permissionMiddleware('system:config:export'), sysConfigController.export);

export default router; 